/*
 * @Author: wangweiruning 
 * @Date: 2021-12-08 17:38:10 
 * @Last Modified by: chenjie
 * @Last Modified time: 2021-12-09 14:06:59
 */
/**通用工具类 */

module.exports = {
    getSafeRandomNum: getSafeRandomNum,
    getRandomNum: getRandomNum,
    isNullOrUndef: isNullOrUndef,
    isDef: isDef,
    isUnDef: isUnDef,
    isNull: isNull
}

// 创建 min-max 之间的随机整数
function getSafeRandomNum(min, max) {
    var seed = (new Date()).getTime();
    seed = (seed * 9301 + 49297) % 233280;
    var rand = seed / (233280.0);
    var range = max - min;
    return Math.floor(rand * (range + 1) + min);
}

// 创建 min-max 之间的随机整数
function getRandomNum(min, max) {
    var range = max - min;
    var rand = Math.random();
    return Math.floor(rand * (range + 1) + min);
}

function isNull(val) {
    return val === null
}

function isDef(val) {
    return typeof val !== 'undefined'
}

function isUnDef(val) {
    return !isDef(val)
}

function isNullOrUndef(val) {
    return isUnDef(val) || isNull(val)
}

/*  使用
  const CommonUtils = require('../../utils/commonUtils')
  CommonUtils.getRandomNum()
 */